/**
 * 消息列表视图工具条.  
 */
var ChatViewToolbar = (function() {

    function _chatDialogToolbar(chatPanel) {
        var _this = this;
        this.chatPanel = chatPanel;
        
        var _chatDialogToolbar = chatPanel.getHeaderToolbarPlaceholder().toolbar({
            cls : 'disperse'
        }).data('toolbar');
        this.toolbar = _chatDialogToolbar;
        this.chatPanel.topBar = _chatDialogToolbar;
         
        var chatGroupEntity = this.chatPanel.chatGroupEntity;
        
        if(chatPanel.mode != 'view'){
            _chatDialogToolbar.addImageButton({
                id : 'closeDialog',
                image : ujs.getRes('images/common24/minimize.png'),
                cls : 'icon imageBtn',
                tooltip : lan('app.im.chatPanel.close'),
                onClick : function() {
                    page.contentCardLayout.showItem('dashboard');
                    sessionList.clearSelection();
                    if(ChatGroupPerm.check(chatGroupEntity['perm'], ChatGroupPerm.DESTRUCTMESSAGE)){
                        _this.chatPanel.chatView.clearMsg();
                    }
                }
            });            
            if(false){                          
                _chatDialogToolbar.addCheckbox({
                    name : 'lockType',
                    labelPos : 'right',                
                    text : 'Scroll Lock',
                    align : 'right',
                    style : 'letter-spacing:1px;font-weight:bold;line-height: 22px;',
                    onChange : function(isSelected){}
                });
            }
        } else {
            if(chatGroupEntity.deleted !== true){
                //start session.
                _chatDialogToolbar.addImageButton({
                    id : 'closeDialog',
                    image : ujs.getRes('images/common24/chat.png'),
                    cls : 'icon imageBtn',
                    tooltip : lan('app.im.chatPanel.chat'),
                    onClick : function() {
                        sessionList.startSession(chatGroupEntity['id']);
                        $('#searchResult').hide();
                        $('.searchBox').val('');
                        page.isSearching = false;
                        sessionList.$wrapper.find('.sessionListItem').filterByText('', '.sessionTitle');
                    }
                });
            }
        }
        
        if(chatGroupEntity.deleted !== true){
            
            if (chatGroupEntity && ChatGroupPerm.check(chatGroupEntity['perm'], ChatGroupPerm.SHOWPARTICIPANTS) || chatGroupEntity['type'] == ChatGroupType.SINGLECHAT) {
                _chatDialogToolbar.addImageButton({
                    id : 'userList',
                    image : ujs.getRes('images/common24/user_group.png'),
                    cls : 'icon imageBtn',
                    tooltip : lan('app.im.chatPanel.showParticipant'),
                    onClick : function() {
                        _this.chatPanel.showParticipants();
                    }
                });
            }
            
            if (chatGroupEntity && chatGroupEntity['type'] != ChatGroupType.SINGLECHAT && ChatGroupPerm.check(chatGroupEntity['perm'], ChatGroupPerm.UPDATE)) {
                _chatDialogToolbar.addImageButton({
                    id : 'edit',
                    image : ujs.getRes('images/common24/edit.png'),
                    cls : 'icon imageBtn',
                    tooltip : lan('app.im.chatPanel.edit'),
                    onClick : function() {
                        ujs.ui.Dialog.get(ChatGroupDialog, {
                            title : lan('app.im.chatPanel.editChat'),
                            mode : 'edit',
                            isBase : true,
                            teid : chatGroupEntity['id']
                        });
                    }                
                });
            }
        }
    }

    return _chatDialogToolbar;
})(); 